package cn.lyf.myblog.controller.view;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;

@Controller
public class User {
    @RequestMapping(value = "/user/index")
    public String index(Model model) throws Exception {
        return "/user/index";
    }

    @RequestMapping("/")
    public String index(HttpSession session) throws Exception {
        if (session.getAttribute("uid") != null)
            return "/user/index";
        return "/toLogin";
    }

    @RequestMapping(value = "/user/about")
    public String about(Model model) throws Exception {
        return "/user/about";
    }

    @RequestMapping(value = "/user/archives")
    public String archives(Model model) throws Exception {
        return "/user/archives";
    }

    @RequestMapping(value = "/user/manage")
    public String manage(Model model) throws Exception {
        return "/user/manage";
    }

    @RequestMapping(value = "/user/publish")
    public String publish(Model model) throws Exception {
        return "/user/publish";
    }

    @RequestMapping(value = "/user/blog")
    public String blog(Model model) throws Exception {
        return "/user/blog";
    }

    @RequestMapping(value = { "/user/labels", "/user/labels/{lid}" })
    public String labels(@PathVariable(required = false) Integer lid, Model model) throws Exception {
        if (lid == null)
            lid = -1;
        model.addAttribute("lid", lid);
        return "/user/labels";
    }

    @RequestMapping(value = { "/user/favorites", "/user/favorites/{fid}" })
    public String favorites(@PathVariable(required = false) Integer fid, Model model) throws Exception {
        if (fid == null)
            fid = -1;
        model.addAttribute("fid", fid);
        return "/user/favorites";
    }
}
